﻿Imports AugmentLib.Database
Imports System.Configuration.ConfigurationManager
Imports AugmentLib.RDLC

Partial Class DocRentTakeUp
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Session.Item("StaffId") Is Nothing Then
            Response.Redirect("default.aspx")
        End If

        If Not Page.IsPostBack Then

            CBEBack.ConfirmText = "You are about to navigate away from this page. " & vbCrLf & "Changes will be discard!"
            CBEDownload.ConfirmText = "All the changes will be saved before you download the document!"

            lblStaffUID.Text = Session.Item("StaffId").ToString
            lblStaffType.Text = Session.Item("StaffType").ToString

            getddlOpenFileRef()

            If Not Session("id") Is Nothing Then
                lblDocId.Text = Me.Session("id").ToString
                pnlEntry.Visible = True
                pnlPreview.Visible = False
                LoadEntry()
                pnlDetails.Visible = True
            Else
                pnlEntry.Visible = True
                pnlPreview.Visible = False
                pnlDetails.Visible = False
            End If
        End If
    End Sub

    Private Sub getddlOpenFileRef()
        Dim TempDT As New Data.DataTable
        Dim objDB As New Database(AppSettings("datasource"), AppSettings("database"), AppSettings("username"), AppSettings("password"), AppSettings("timeout"), AppSettings("pooling"))
        objDB.OpenConnection()

        'Only display records that pending signing, pending collection and completed. New, relist or renew's record will not display here.
        If lblStaffType.Text = "2" Then 'ren
            objDB.dbVariable.SQLString = "SELECT OpenFileRef FROM AW_RentTransaction WHERE TransactorId=@TransactorId " & _
                                   "AND Status in ('1','2','3')"
            objDB.AddParameter("TransactorId", Data.SqlDbType.UniqueIdentifier, New Guid(lblStaffUID.Text))
        Else
            'admin/boss
            objDB.dbVariable.SQLString = "SELECT OpenFileRef FROM AW_RentTransaction WHERE Status in ('1','2','3')"
        End If

        objDB.FillData(TempDT, "AW_RentTransaction", Database.SQLCommandType.NormalString)

        objDB.CloseConnection()

        ddlOpenRefNo.DataSource = TempDT
        ddlOpenRefNo.DataTextField = "OpenFileRef"
        ddlOpenRefNo.DataValueField = "OpenFileRef"
        ddlOpenRefNo.DataBind()
        ddlOpenRefNo.Items.Insert(0, "-SELECT-")
        ddlOpenRefNo.Items(0).Value = ""
    End Sub

    Private Sub LoadEntry()
        Dim TempDT As New Data.DataTable
        TempDT = LoadDocRent()
        For Each dtrow As Data.DataRow In TempDT.Rows
            txtTitle.Text = dtrow.Item("DocRentTitle").ToString
            lblTransactionId.Text = dtrow.Item("TransactionId").ToString
            If IsError(ddlOpenRefNo.SelectedValue = dtrow.Item("DocOpenRefNo").ToString) Then
                ddlOpenRefNo.Items.Insert(1, dtrow.Item("DocOpenRefNo").ToString)
                ddlOpenRefNo.Items(1).Value = dtrow.Item("DocOpenRefNo").ToString
                ddlOpenRefNo.Items(1).Selected = True
            Else
                ddlOpenRefNo.SelectedValue = dtrow.Item("DocOpenRefNo").ToString
            End If
            lblTransact.Text = dtrow.Item("Category").ToString
            lblTransactBy.Text = dtrow.Item("REN").ToString
            lblListBy.Text = dtrow.Item("Lister").ToString
            If dtrow.Item("DocDate").ToString = "" Then
                txtdate.text = ""
            Else
                txtDate.Text = Format(dtrow.Item("DocDate"), "dd-MMM-yyy")
            End If
            lblPremise.Text = dtrow.Item("Premise").ToString
            lblMonthlyRental.Text = dtrow.Item("MonthlyRental").ToString
            lblDuration.Text = dtrow.Item("Duration").ToString
            lblDurationType.Text = dtrow.Item("DurationType").ToString
            txtAnother.Text = dtrow.Item("AnotherDuration").ToString
            ddlModeOfPayment.SelectedValue = dtrow.Item("AnotherType").ToString()
            ddlUpon.SelectedValue = dtrow.Item("UponAt").ToString
            txtIncrease.Text = dtrow.Item("Increase").ToString
            If dtrow.Item("CommencementDate").ToString = "" Then
                lblCommencementDate.Text = ""
            Else
                lblCommencementDate.Text = Format(dtrow.Item("CommencementDate"), "dd-MMM-yyyy")
            End If
            lblUseOfPremise.Text = dtrow.Item("PremisesUse").ToString
            lblTerminationClause.Text = dtrow.Item("TerminationClause").ToString
            lblRentFreePeriod.Text = dtrow.Item("RentFreePeriod").ToString
            lblRequisition.Text = dtrow.Item("Requisition").ToString
            lblLName.Text = dtrow.Item("LandlordName").ToString
            lblLNRIC.Text = dtrow.Item("LandlordNRIC").ToString
            lblLAddress.Text = dtrow.Item("LandlordAddress").ToString
            lblContacPerson.Text = dtrow.Item("LandlordContactPerson").ToString
            lblLTel.Text = dtrow.Item("LandlordTel").ToString
            lblLFax.Text = dtrow.Item("LandlordFax").ToString
            lblMobile.Text = dtrow.Item("LandlordMobile").ToString
            lblVMT.Text = dtrow.Item("LandlordVMT").ToString
            lblAgencyFee.Text = dtrow.Item("AgencyFee").ToString
            lblGovTax.Text = dtrow.Item("GovTax").ToString
            lblGovPercent.Text = dtrow.Item("GovPercent").ToString
            lblLTA.Text = dtrow.Item("LandlordTA").ToString
            lblLStampingFee.Text = dtrow.Item("LandlordStampingFee").ToString
            txtBankAcc.Text = dtrow.Item("BankAcc").ToString
            lblTName.Text = dtrow.Item("TenantName").ToString
            lblTNRIC.Text = dtrow.Item("TenantNRIC").ToString
            lblTAddress.Text = dtrow.Item("TenantAddress").ToString
            lblTContactPerson.Text = dtrow.Item("TenantContactPerson").ToString
            lblTTelNo.Text = dtrow.Item("TenantTel").ToString
            lblTFaxNo.Text = dtrow.Item("TenantFax").ToString
            lblTMobile.Text = dtrow.Item("TenantMobile").ToString
            lblTVMT.Text = dtrow.Item("TenantVMT").ToString
            lblDeposit.Text = dtrow.Item("Deposit").ToString
            lblDepositMonth.Text = dtrow.Item("DepositMonth").ToString
            lblAdvance.Text = dtrow.Item("Advance").ToString
            lblAdvanceMonth.Text = dtrow.Item("AdvanceMonth").ToString
            lblTWEDeposit.Text = dtrow.Item("WEDeposit").ToString
            lblDisbursement.Text = dtrow.Item("Disbursement").ToString
            lblTTA.Text = dtrow.Item("TenantTA").ToString
            lblTStampingFee.Text = dtrow.Item("TenantStampingFee").ToString
            lblReferralFee.Text = dtrow.Item("ReferralFee").ToString
            lblUpdated.Text = "Last Updated By : " & dtrow.Item("CreateBy").ToString & " on " & Format(dtrow.Item("CreateDate"), "dd-MMM-yyyy")
        Next

    End Sub

    Private Function LoadDocRent() As Data.DataTable
        Dim objDB As New Database(AppSettings("datasource"), AppSettings("database"), AppSettings("username"), AppSettings("password"), AppSettings("timeout"), AppSettings("pooling"))
        Dim TempDT As New Data.DataTable

        objDB.OpenConnection()

        objDB.dbVariable.SQLString = "SELECT d.DocRentTitle, d.DocOpenRefNo, d.TransactionId, d.Category, d.REN, d.Lister, d.DocDate, d.MonthlyRental, d.Premise, " & _
                                    "d.Duration, d.DurationType, d.AnotherDuration, d.AnotherType, d.UponAt, d.Increase, " & _
                                    "d.CommencementDate, d.PremisesUse, d.TerminationClause, d.RentFreePeriod, d.Requisition, " & _
                                    "d.LandlordName, d.LandlordNRIC, d.LandlordAddress, d.LandlordContactPerson, " & _
                                    "d.LandlordTel, d.LandlordFax, d.LandlordMobile, d.LandlordVMT, d.AgencyFee, d.GovTax, " & _
                                    "d.GovPercent, d.LandlordTA, d.LandlordStampingFee, d.BankAcc, d.TenantName, d.TenantNRIC, " & _
                                    "d.TenantAddress, d.TenantContactPerson, d.TenantTel, d.TenantFax, d.TenantMobile, " & _
                                    "d.TenantVMT, d.DepositMonth, d.Deposit, d.AdvanceMonth, d.Advance, d.WEDeposit, " & _
                                    "d.Disbursement, d.TenantTA, d.TenantStampingFee, d.ReferralFee, ISNULL(d.UpdateDate, d.CreateDate) as CreateDate, " & _
                                    "ISNULL(u.Initial, c.Initial) as CreateBy, d.StatusDelete FROM AW_DocTakeUpRent d " & _
                                    "LEFT JOIN AW_Staff u ON d.UpdateBy = u.StaffId LEFT JOIN AW_Staff c ON " & _
                                    "d.CreateBy = c.StaffId WHERE DocRentId=@DocRentId"
        objDB.AddParameter("DocRentId", Data.SqlDbType.UniqueIdentifier, New Guid(lblDocId.Text))
        objDB.FillData(TempDT, "DocTakeUpRent", Database.SQLCommandType.NormalString)
        objDB.CloseConnection()
        Return TempDT
    End Function

    Protected Sub btnRefresh_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnRefresh.Click
        Dim objDB As New Database(AppSettings("datasource"), AppSettings("database"), AppSettings("username"), AppSettings("password"), AppSettings("timeout"), AppSettings("pooling"))
        Dim TempDT As New Data.DataTable

        objDB.OpenConnection()

        objDB.dbVariable.SQLString = "SELECT RT.TransactionId, CASE RT.TransListType WHEN '1' THEN 'RR' WHEN '2' THEN 'RC' WHEN '3' " & _
                                    "THEN 'RL' WHEN '4' THEN 'RI' ELSE '' END as Category, tr.Name as REN, li.Name as Lister, " & _
                                    "p.PropertyId, p.UnitNumber + ', ' + r.Road + ', ' + l.Location + ', ' + s.State + ', ' + c.Country as 'Address', " & _
                                    "RT.MonthlyRental, RT.TenancyDuration, CASE RT.TenancyDurationType WHEN '0' THEN 'year' WHEN '1' " & _
                                    "THEN 'month' WHEN '2' THEN 'day' ELSE '' END as TenancyDurationType, RT.CommencementDate, " & _
                                    "RT.PremiseUse, RT.TerminationClause, CASE RT.RentFreePeriodType WHEN '1' THEN 'year' WHEN '2' THEN 'month' " & _
                                    "WHEN '3' THEN 'day' ELSE '' END as RentFreePeriodType, RT.RentFreePeriod, RT.Requisition, " & _
                                    "CASE RT.TenantType WHEN '1' THEN RT.TenantCompany WHEN '0' THEN RT.TenantName1 ELSE '' END as TenantName, " & _
                                    "CASE RT.TenantType WHEN '1' THEN RT.TenantCompanyNo WHEN '0' THEN RT.TenantNRIC1 ELSE '' END as TenantNo, " & _
                                    "RT.TenantAddress, RT.TenantContactPerson, RT.TenantPhone, RT.TenantFax, RT.TenantMobile, RT.TenantEmail, " & _
                                    "RT.TenantViewMeetTele, CASE RT.LandlordType WHEN '1' THEN RT.LandlordCompany WHEN '0' THEN RT.LandlordName1 " & _
                                    "ELSE '' END as LandlordName, CASE RT.LandlordType WHEN '1' THEN RT.LandlordCompanyNo WHEN '0' THEN RT.LandlordNRIC1 ELSE '' END " & _
                                    "as LandlordNo, RT.LandlordAddress, RT.LandlordContactPerson, RT.LandlordPhone, RT.LandlordMobile, " & _
                                    "RT.LandlordFax, RT.LandlordEmail, RT.LandlordViewMeetTele, RT.AgencyFee, RT.GST, RT.GovAmt, RT.LandlordTAFee, " & _
                                    "RT.StampDuty/2 as StampingFee, RT.DepositMonth, RT.Deposit, RT.AdvanceMonth, RT.Advance, RT.WaterElectric, " & _
                                    "RT.DisbursementFee, RT.TenantTAFee, RT.ReferralAmt FROM AW_RentTransaction RT LEFT JOIN AW_Property p ON " & _
                                    "RT.PropertyId=P.PropertyId LEFT JOIN AW_Road r ON p.RoadId=r.RoadId LEFT JOIN AW_Location l ON r.LocationId = l.LocationId " & _
                                    "LEFT JOIN AW_State s ON L.StateId=s.StateId LEFT JOIN AW_Country c ON s.CountryId=c.CountryId LEFT JOIN AW_Staff tr " & _
                                    "ON RT.TransactorId=tr.StaffId LEFT JOIN AW_Staff li ON RT.ListerId=li.StaffId WHERE RT.OpenFileRef=@OpenFileRef "
        objDB.AddParameter("OpenFileRef", Data.SqlDbType.NVarChar, ddlOpenRefNo.SelectedValue)
        objDB.FillData(TempDT, "AW_RentTransaction", Database.SQLCommandType.NormalString)
        objDB.CloseConnection()

        For Each dr As Data.DataRow In TempDT.Rows
            lblTransactionId.Text = dr.Item("TransactionId").ToString
            lblTransact.Text = dr.Item("Category").ToString
            lblTransactBy.Text = dr.Item("REN").ToString
            lblListBy.Text = dr.Item("Lister").ToString
            lblPremise.Text = dr.Item("Address").ToString
            lblMonthlyRental.Text = dr.Item("MonthlyRental").ToString
            lblDuration.Text = dr.Item("TenancyDuration").ToString
            lblDurationType.Text = dr.Item("TenancyDurationType").ToString
            If dr.Item("CommencementDate").ToString = "" Then
                lblCommencementDate.Text = ""
            Else
                lblCommencementDate.Text = Format(dr.Item("CommencementDate"), "dd-MMM-yyyy")
            End If
            lblUseOfPremise.Text = dr.Item("PremiseUse").ToString
            lblTerminationClause.Text = dr.Item("TerminationClause").ToString
            lblRentFreePeriod.Text = dr.Item("RentFreePeriod").ToString & " " & dr.Item("RentFreePeriodType")
            lblRequisition.Text = dr.Item("Requisition").ToString
            lblLName.Text = dr.Item("LandlordName").ToString
            lblLNRIC.Text = dr.Item("LandlordNo").ToString
            lblLAddress.Text = dr.Item("LandlordAddress").ToString
            lblContacPerson.Text = dr.Item("LandlordContactPerson").ToString
            lblLTel.Text = dr.Item("LandlordPhone").ToString
            lblLFax.Text = dr.Item("LandlordFax").ToString
            lblMobile.Text = dr.Item("LandlordMobile").ToString
            lblVMT.Text = dr.Item("LandlordViewMeetTele").ToString
            lblAgencyFee.Text = dr.Item("AgencyFee").ToString
            lblGovTax.Text = dr.Item("GovAmt").ToString
            lblGovPercent.Text = dr.Item("GST").ToString
            lblLTA.Text = dr.Item("LandlordTAFee").ToString
            lblLStampingFee.Text = dr.Item("StampingFee").ToString
            lblTName.Text = dr.Item("TenantName").ToString
            lblTNRIC.Text = dr.Item("TenantNo").ToString
            lblTAddress.Text = dr.Item("TenantAddress").ToString
            lblTContactPerson.Text = dr.Item("TenantContactPerson").ToString
            lblTTelNo.Text = dr.Item("TenantPhone").ToString
            lblTFaxNo.Text = dr.Item("TenantFax").ToString
            lblTMobile.Text = dr.Item("TenantMobile").ToString
            lblTVMT.Text = dr.Item("TenantViewMeetTele").ToString
            lblDeposit.Text = dr.Item("Deposit").ToString
            lblDepositMonth.Text = dr.Item("DepositMonth").ToString
            lblAdvance.Text = dr.Item("Advance").ToString
            lblAdvanceMonth.Text = dr.Item("AdvanceMonth").ToString
            lblTWEDeposit.Text = dr.Item("WaterElectric").ToString
            lblDisbursement.Text = dr.Item("DisbursementFee").ToString
            lblTTA.Text = dr.Item("TenantTAFee").ToString
            lblTStampingFee.Text = dr.Item("StampingFee").ToString
            lblReferralFee.Text = dr.Item("ReferralAmt").ToString
        Next

        pnlDetails.Visible = True

    End Sub

    Protected Sub BtnSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BtnSave.Click
        Dim objDB As New Database(AppSettings("datasource"), AppSettings("database"), AppSettings("username"), AppSettings("password"), AppSettings("timeout"), AppSettings("pooling"))
        Try
            objDB.OpenConnection()
            objDB.InitDbTrans()
            Dim DocExId As String
            If lblDocId.Text = String.Empty Then
                objDB.dbVariable.SQLString = "INSERT INTO AW_DocTakeUpRent(DocRentId, DocRentTitle, DocOpenRefNo, TransactionId, Category, REN, Lister, " & _
                                            "DocDate, Premise, MonthlyRental, Duration, DurationType, AnotherDuration, " & _
                                            "AnotherType, UponAt, Increase, CommencementDate, PremisesUse, TerminationClause, " & _
                                            "RentFreePeriod, Requisition, LandlordName, LandlordNRIC, LandlordAddress, " & _
                                            "LandlordContactPerson, LandlordTel, LandlordFax, LandlordMobile, LandlordVMT, " & _
                                            "AgencyFee, GovTax, GovPercent, LandlordTA, LandlordStampingFee, BankAcc, TenantName, " & _
                                            "TenantNRIC, TenantAddress, TenantContactPerson, TenantTel, TenantFax, TenantMobile, " & _
                                            "TenantVMT, DepositMonth, Deposit, AdvanceMonth, Advance, WEDeposit, Disbursement, TenantTA, " & _
                                            "TenantStampingFee, ReferralFee, CreateDate, CreateBy, UpdateDate, UpdateBy, StatusDelete) " & _
                                            "VALUES (@DocRentId, @DocRentTitle, @DocOpenRefNo, @TransactionId, @Category, @REN, @Lister, " & _
                                            "@DocDate, @Premise, @MonthlyRental, @Duration, @DurationType, @AnotherDuration, " & _
                                            "@AnotherType, @UponAt, @Increase, @CommencementDate, @PremisesUse, @TerminationClause, " & _
                                            "@RentFreePeriod, @Requisition, @LandlordName, @LandlordNRIC, @LandlordAddress, " & _
                                            "@LandlordContactPerson, @LandlordTel, @LandlordFax, @LandlordMobile, @LandlordVMT, " & _
                                            "@AgencyFee, @GovTax, @GovPercent, @LandlordTA, @LandlordStampingFee, @BankAcc, @TenantName, " & _
                                            "@TenantNRIC, @TenantAddress, @TenantContactPerson, @TenantTel, @TenantFax, @TenantMobile, " & _
                                            "@TenantVMT, @DepositMonth, @Deposit, @AdvanceMonth, @Advance, @WEDeposit, @Disbursement, @TenantTA, " & _
                                            "@TenantStampingFee, @ReferralFee, @CreateDate, @CreateBy, @UpdateDate, @UpdateBy, @StatusDelete)"
                DocExId = Guid.NewGuid.ToString
                lblDocId.Text = DocExId
                lblUpdated.Text = "Created By : " & GetName() & " on " & Format(Now(), "dd-MMM-yyyy")
                objDB.AddParameter("UpdateDate", Data.SqlDbType.DateTime, DBNull.Value)
                objDB.AddParameter("UpdateBy", Data.SqlDbType.UniqueIdentifier, DBNull.Value)
            Else
                objDB.dbVariable.SQLString = "UPDATE AW_DocTakeUpRent SET DocRentTitle=@DocRentTitle, DocOpenRefNo=@DocOpenRefNo, TransactionId=@TransactionId, Category=@Category, " & _
                                            "REN=@REN, Lister=@Lister, DocDate=@DocDate, Premise=@Premise, MonthlyRental=@MonthlyRental, " & _
                                            "Duration=@Duration, DurationType=@DurationType, AnotherDuration=@AnotherDuration, " & _
                                            "AnotherType=@AnotherType, UponAt=@UponAt, Increase=@Increase, CommencementDate=@CommencementDate, " & _
                                            "PremisesUse=@PremisesUse, TerminationClause=@TerminationClause, RentFreePeriod=@RentFreePeriod, " & _
                                            "Requisition=@Requisition, LandlordName=@LandlordName, LandlordNRIC=@LandlordNRIC, " & _
                                            "LandlordAddress=@LandlordAddress, LandlordContactPerson=@LandlordContactPerson, " & _
                                            "LandlordTel=@LandlordTel, LandlordFax=@LandlordFax, LandlordMobile=@LandlordMobile, " & _
                                            "LandlordVMT=@LandlordVMT, AgencyFee=@AgencyFee, GovTax=@GovTax, GovPercent=@GovPercent, " & _
                                            "LandlordTA=@LandlordTA, LandlordStampingFee=@LandlordStampingFee, BankAcc=@BankAcc, " & _
                                            "TenantName=@TenantName, TenantNRIC=@TenantNRIC, TenantAddress=@TenantAddress, " & _
                                            "TenantContactPerson=@TenantContactPerson, TenantTel=@TenantTel, TenantFax=@TenantFax, " & _
                                            "TenantMobile=@TenantMobile, TenantVMT=@TenantVMT, DepositMonth=@DepositMonth, Deposit=@Deposit, " & _
                                            "AdvanceMonth=@AdvanceMonth, Advance=@Advance, WEDeposit=@WEDeposit, Disbursement=@Disbursement, " & _
                                            "TenantTA=@TenantTA, TenantStampingFee=@TenantStampingFee, ReferralFee=@ReferralFee, UpdateDate=@UpdateDate, " & _
                                            "UpdateBy=@UpdateBy WHERE DocRentId=@DocRentId"
                DocExId = lblDocId.Text.Trim
                lblUpdated.Text = "Last Updated By : " & GetName() & " on " & Format(Now(), "dd-MMM-yyyy")
                objDB.AddParameter("UpdateDate", Data.SqlDbType.DateTime, Now())
                objDB.AddParameter("UpdateBy", Data.SqlDbType.UniqueIdentifier, New Guid(lblStaffUID.Text))
            End If
            objDB.AddParameter("DocRentId", Data.SqlDbType.UniqueIdentifier, New Guid(DocExId))
            objDB.AddParameter("DocRentTitle", Data.SqlDbType.NVarChar, txtTitle.Text.Trim.ToUpper)
            objDB.AddParameter("DocOpenRefNo", Data.SqlDbType.NVarChar, ddlOpenRefNo.SelectedValue)
            objDB.AddParameter("TransactionId", Data.SqlDbType.UniqueIdentifier, New Guid(lblTransactionId.Text))
            If lblTransact.Text = String.Empty Then
                objDB.AddParameter("Category", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("Category", Data.SqlDbType.NVarChar, lblTransact.Text.Trim)
            End If
            If lblTransactBy.Text = String.Empty Then
                objDB.AddParameter("REN", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("REN", Data.SqlDbType.NVarChar, lblTransactBy.Text.Trim)
            End If
            If lblListBy.Text = String.Empty Then
                objDB.AddParameter("Lister", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("Lister", Data.SqlDbType.NVarChar, lblListBy.Text.Trim)
            End If
            If txtDate.Text = String.Empty Then
                objDB.AddParameter("DocDate", Data.SqlDbType.DateTime, DBNull.Value)
            Else
                objDB.AddParameter("DocDate", Data.SqlDbType.DateTime, DateTime.ParseExact(txtDate.Text.Trim, "dd-MMM-yyyy", Nothing))
            End If
            If lblPremise.Text = String.Empty Then
                objDB.AddParameter("Premise", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("Premise", Data.SqlDbType.NVarChar, lblPremise.Text.Trim)
            End If
            If lblMonthlyRental.Text = String.Empty Then
                objDB.AddParameter("MonthlyRental", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("MonthlyRental", Data.SqlDbType.NVarChar, lblMonthlyRental.Text.Trim)
            End If
            If lblDuration.Text = String.Empty Then
                objDB.AddParameter("Duration", Data.SqlDbType.Decimal, DBNull.Value)
            Else
                objDB.AddParameter("Duration", Data.SqlDbType.Decimal, CDbl(lblDuration.Text.Trim))
            End If
            If lblDurationType.Text = String.Empty Then
                objDB.AddParameter("DurationType", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("DurationType", Data.SqlDbType.NVarChar, lblDurationType.Text)
            End If
            If txtAnother.Text = String.Empty Then
                objDB.AddParameter("AnotherDuration", Data.SqlDbType.Decimal, DBNull.Value)
            Else
                objDB.AddParameter("AnotherDuration", Data.SqlDbType.Decimal, CDbl(txtAnother.Text.Trim))
            End If
            objDB.AddParameter("AnotherType", Data.SqlDbType.NVarChar, ddlModeOfPayment.SelectedValue)
            objDB.AddParameter("UponAt", Data.SqlDbType.NVarChar, ddlUpon.SelectedValue)
            If txtIncrease.Text = String.Empty Then
                objDB.AddParameter("Increase", Data.SqlDbType.Decimal, DBNull.Value)
            Else
                objDB.AddParameter("Increase", Data.SqlDbType.Decimal, CDbl(txtIncrease.Text.Trim))
            End If
            If lblCommencementDate.Text = String.Empty Then
                objDB.AddParameter("CommencementDate", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("CommencementDate", Data.SqlDbType.NVarChar, lblCommencementDate.Text)
            End If
            If lblUseOfPremise.Text = String.Empty Then
                objDB.AddParameter("PremisesUse", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("PremisesUse", Data.SqlDbType.NVarChar, lblUseOfPremise.Text)
            End If
            If lblTerminationClause.Text = String.Empty Then
                objDB.AddParameter("TerminationClause", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("TerminationClause", Data.SqlDbType.NVarChar, lblTerminationClause.Text)
            End If
            If lblRentFreePeriod.Text = String.Empty Then
                objDB.AddParameter("RentFreePeriod", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("RentFreePeriod", Data.SqlDbType.NVarChar, lblRentFreePeriod.Text)
            End If
            If lblRequisition.Text = String.Empty Then
                objDB.AddParameter("Requisition", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("Requisition", Data.SqlDbType.NVarChar, lblRequisition.Text)
            End If
            If lblLName.Text = String.Empty Then
                objDB.AddParameter("LandlordName", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("LandlordName", Data.SqlDbType.NVarChar, lblLName.Text)
            End If
            If lblLNRIC.Text = String.Empty Then
                objDB.AddParameter("LandlordNRIC", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("LandlordNRIC", Data.SqlDbType.NVarChar, lblLNRIC.Text)
            End If
            If lblLAddress.Text = String.Empty Then
                objDB.AddParameter("LandlordAddress", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("LandlordAddress", Data.SqlDbType.NVarChar, lblLAddress.Text)
            End If
            If lblContacPerson.Text = String.Empty Then
                objDB.AddParameter("LandlordContactPerson", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("LandlordContactPerson", Data.SqlDbType.NVarChar, lblContacPerson.Text)
            End If
            If lblLTel.Text = String.Empty Then
                objDB.AddParameter("LandlordTel", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("LandlordTel", Data.SqlDbType.NVarChar, lblLTel.Text)
            End If
            If lblLFax.Text = String.Empty Then
                objDB.AddParameter("LandlordFax", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("LandlordFax", Data.SqlDbType.NVarChar, lblLFax.Text)
            End If
            If lblMobile.Text = String.Empty Then
                objDB.AddParameter("LandlordMobile", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("LandlordMobile", Data.SqlDbType.NVarChar, lblMobile.Text)
            End If
            If lblVMT.Text = String.Empty Then
                objDB.AddParameter("LandlordVMT", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("LandlordVMT", Data.SqlDbType.NVarChar, lblVMT.Text)
            End If
            If lblAgencyFee.Text = String.Empty Then
                objDB.AddParameter("AgencyFee", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("AgencyFee", Data.SqlDbType.NVarChar, lblAgencyFee.Text)
            End If
            If lblGovTax.Text = String.Empty Then
                objDB.AddParameter("GovTax", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("GovTax", Data.SqlDbType.NVarChar, lblGovTax.Text)
            End If
            If lblGovPercent.Text = String.Empty Then
                objDB.AddParameter("GovPercent", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("GovPercent", Data.SqlDbType.NVarChar, lblGovPercent.Text)
            End If
            If lblLTA.Text = String.Empty Then
                objDB.AddParameter("LandlordTA", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("LandlordTA", Data.SqlDbType.NVarChar, lblLTA.Text)
            End If
            If lblLStampingFee.Text = String.Empty Then
                objDB.AddParameter("LandlordStampingFee", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("LandlordStampingFee", Data.SqlDbType.NVarChar, lblLStampingFee.Text)
            End If
            If txtBankAcc.Text = String.Empty Then
                objDB.AddParameter("BankAcc", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("BankAcc", Data.SqlDbType.NVarChar, txtBankAcc.Text)
            End If
            If lblTName.Text = String.Empty Then
                objDB.AddParameter("TenantName", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("TenantName", Data.SqlDbType.NVarChar, lblTName.Text)
            End If
            If lblTNRIC.Text = String.Empty Then
                objDB.AddParameter("TenantNRIC", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("TenantNRIC", Data.SqlDbType.NVarChar, lblTNRIC.Text)
            End If
            If lblTAddress.Text = String.Empty Then
                objDB.AddParameter("TenantAddress", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("TenantAddress", Data.SqlDbType.NVarChar, lblTAddress.Text)
            End If
            If lblTContactPerson.Text = String.Empty Then
                objDB.AddParameter("TenantContactPerson", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("TenantContactPerson", Data.SqlDbType.NVarChar, lblTContactPerson.Text)
            End If
            If lblTTelNo.Text = String.Empty Then
                objDB.AddParameter("TenantTel", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("TenantTel", Data.SqlDbType.NVarChar, lblTTelNo.Text)
            End If
            If lblTFaxNo.Text = String.Empty Then
                objDB.AddParameter("TenantFax", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("TenantFax", Data.SqlDbType.NVarChar, lblTFaxNo.Text)
            End If
            If lblTMobile.Text = String.Empty Then
                objDB.AddParameter("TenantMobile", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("TenantMobile", Data.SqlDbType.NVarChar, lblTMobile.Text)
            End If
            If lblTVMT.Text = String.Empty Then
                objDB.AddParameter("TenantVMT", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("TenantVMT", Data.SqlDbType.NVarChar, lblTVMT.Text)
            End If
            If lblDepositMonth.Text = String.Empty Then
                objDB.AddParameter("DepositMonth", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("DepositMonth", Data.SqlDbType.NVarChar, lblDepositMonth.Text)
            End If
            If lblDeposit.Text = String.Empty Then
                objDB.AddParameter("Deposit", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("Deposit", Data.SqlDbType.NVarChar, lblDeposit.Text)
            End If
            If lblAdvanceMonth.Text = String.Empty Then
                objDB.AddParameter("AdvanceMonth", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("AdvanceMonth", Data.SqlDbType.NVarChar, lblAdvanceMonth.Text)
            End If
            If lblAdvance.Text = String.Empty Then
                objDB.AddParameter("Advance", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("Advance", Data.SqlDbType.NVarChar, lblAdvance.Text)
            End If
            If lblTWEDeposit.Text = String.Empty Then
                objDB.AddParameter("WEDeposit", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("WEDeposit", Data.SqlDbType.NVarChar, lblTWEDeposit.Text)
            End If
            If lblDisbursement.Text = String.Empty Then
                objDB.AddParameter("Disbursement", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("Disbursement", Data.SqlDbType.NVarChar, lblDisbursement.Text)
            End If
            If lblTTA.Text = String.Empty Then
                objDB.AddParameter("TenantTA", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("TenantTA", Data.SqlDbType.NVarChar, lblTTA.Text)
            End If
            If lblTStampingFee.Text = String.Empty Then
                objDB.AddParameter("TenantStampingFee", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("TenantStampingFee", Data.SqlDbType.NVarChar, lblTStampingFee.Text)
            End If
            If lblReferralFee.Text = String.Empty Then
                objDB.AddParameter("ReferralFee", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("ReferralFee", Data.SqlDbType.NVarChar, lblReferralFee.Text)
            End If
            objDB.AddParameter("CreateDate", Data.SqlDbType.DateTime, Now())
            objDB.AddParameter("CreateBy", Data.SqlDbType.UniqueIdentifier, New Guid(lblStaffUID.Text))
            objDB.AddParameter("StatusDelete", Data.SqlDbType.TinyInt, 0)
            objDB.ExecuteQuery()
            objDB.DbTransCommit()
            objDB.CloseConnection()
            lblDocId.Text = DocExId
        Catch ex As Exception
            objDB.DbTransRollback()
            If objDB.dbVariable.objConn.State = Data.ConnectionState.Open Then
                objDB.CloseConnection()
            End If
            lblMsgError.Text = ex.Message
            divError.Visible = True
        End Try
    End Sub

    Private Function GetName() As String
        Dim objDB As New Database(AppSettings("datasource"), AppSettings("database"), AppSettings("username"), AppSettings("password"), AppSettings("timeout"), AppSettings("pooling"))
        Dim TempDT As New Data.DataTable
        Dim StaffName As String = String.Empty

        objDB.OpenConnection()

        objDB.dbVariable.SQLString = "SELECT Name FROM AW_Staff WHERE StaffId=@StaffId"
        objDB.AddParameter("StaffId", Data.SqlDbType.UniqueIdentifier, New Guid(lblStaffUID.Text))
        objDB.FillData(TempDT, "AW_Staff", Database.SQLCommandType.NormalString)
        objDB.CloseConnection()

        For Each dtrow As Data.DataRow In TempDT.Rows
            If dtrow.Item("Name").ToString <> "" Then
                StaffName = dtrow.Item("Name").ToString
            End If
        Next

        Return StaffName
    End Function

    Protected Sub btnPreview_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnPreview.Click
        pnlEntry.Visible = False
        pnlPreview.Visible = True

        Dim TempDT As New Data.DataTable
        Dim CommissionDT As New Data.DataTable
        Dim GrandTotal As Decimal = 0

        'TempDT = LoadDocRent()
        DeclareColumnTempDT(TempDT)
        Dim MyRow As Data.DataRow
        MyRow = TempDT.NewRow()
        MyRow(0) = txtTitle.Text.Trim.ToUpper
        MyRow(1) = ddlOpenRefNo.SelectedValue
        MyRow(2) = lblTransactionId.Text.Trim
        MyRow(3) = lblTransact.Text.Trim
        MyRow(4) = lblTransactBy.Text.Trim
        MyRow(5) = lblListBy.Text.Trim
        If txtDate.Text = String.Empty Then
            MyRow(6) = DBNull.Value
        Else
            MyRow(6) = DateTime.ParseExact(txtDate.Text.Trim, "dd-MMM-yyyy", Nothing)
        End If
        MyRow(7) = lblPremise.Text.Trim
        If lblMonthlyRental.Text = String.Empty Then
            MyRow(8) = DBNull.Value
        Else
            MyRow(8) = CDbl(lblMonthlyRental.Text.Trim)
        End If
        If lblDuration.Text = String.Empty Then
            MyRow(9) = DBNull.Value
        Else
            MyRow(9) = CDbl(lblDuration.Text.Trim)
        End If
        MyRow(10) = lblDurationType.Text.Trim
        If txtAnother.Text = String.Empty Then
            MyRow(11) = DBNull.Value
        Else
            MyRow(11) = CDbl(txtAnother.Text.Trim)
        End If
        MyRow(12) = ddlModeOfPayment.SelectedValue
        MyRow(13) = ddlUpon.SelectedValue
        If txtIncrease.Text = String.Empty Then
            MyRow(14) = DBNull.Value
        Else
            MyRow(14) = CDbl(txtIncrease.Text.Trim)
        End If
        If lblCommencementDate.Text = String.Empty Then
            MyRow(15) = DBNull.Value
        Else
            MyRow(15) = DateTime.ParseExact(lblCommencementDate.Text.Trim, "dd-MMM-yyyy", Nothing)
        End If
        MyRow(16) = lblUseOfPremise.Text.Trim
        MyRow(17) = lblTerminationClause.Text.Trim
        MyRow(18) = lblRentFreePeriod.Text.Trim
        MyRow(19) = lblRequisition.Text.Trim
        MyRow(20) = lblLName.Text.Trim
        MyRow(21) = lblLNRIC.Text.Trim
        MyRow(22) = lblLAddress.Text.Trim
        MyRow(23) = lblContacPerson.Text.Trim
        MyRow(24) = lblLTel.Text.Trim
        MyRow(25) = lblLFax.Text.Trim
        MyRow(26) = lblMobile.Text.Trim
        MyRow(27) = lblVMT.Text.Trim
        If lblAgencyFee.Text = String.Empty Then
            MyRow(28) = DBNull.Value
        Else
            MyRow(28) = CDbl(lblAgencyFee.Text.Trim)
        End If
        If lblGovTax.Text = String.Empty Then
            MyRow(29) = DBNull.Value
        Else
            MyRow(29) = CDbl(lblGovTax.Text.Trim)
        End If
        If lblGovPercent.Text = String.Empty Then
            MyRow(30) = DBNull.Value
        Else
            MyRow(30) = CDbl(lblGovPercent.Text.Trim)
        End If
        If lblLTA.Text = String.Empty Then
            MyRow(31) = DBNull.Value
        Else
            MyRow(31) = CDbl(lblLTA.Text.Trim)
        End If
        If lblLStampingFee.Text = String.Empty Then
            MyRow(32) = DBNull.Value
        Else
            MyRow(32) = CDbl(lblLStampingFee.Text.Trim)
        End If
        MyRow(33) = txtBankAcc.Text.Trim
        MyRow(34) = lblTName.Text.Trim
        MyRow(35) = lblLNRIC.Text.Trim
        MyRow(36) = lblTAddress.Text.Trim
        MyRow(37) = lblTContactPerson.Text.Trim
        MyRow(38) = lblTTelNo.Text.Trim
        MyRow(39) = lblTFaxNo.Text.Trim
        MyRow(40) = lblTMobile.Text.Trim
        MyRow(41) = lblTVMT.Text.Trim
        If lblDepositMonth.Text = String.Empty Then
            MyRow(42) = DBNull.Value
        Else
            MyRow(42) = CDbl(lblDepositMonth.Text.Trim)
        End If
        If lblDeposit.Text = String.Empty Then
            MyRow(43) = DBNull.Value
        Else
            MyRow(43) = CDbl(lblDeposit.Text.Trim)
        End If
        If lblAdvanceMonth.Text = String.Empty Then
            MyRow(44) = DBNull.Value
        Else
            MyRow(44) = CDbl(lblAdvanceMonth.Text.Trim)
        End If
        If lblAdvance.Text = String.Empty Then
            MyRow(45) = DBNull.Value
        Else
            MyRow(45) = CDbl(lblAdvance.Text.Trim)
        End If
        If lblTWEDeposit.Text = String.Empty Then
            MyRow(46) = DBNull.Value
        Else
            MyRow(46) = CDbl(lblTWEDeposit.Text.Trim)
        End If
        If lblDisbursement.Text = String.Empty Then
            MyRow(47) = DBNull.Value
        Else
            MyRow(47) = CDbl(lblDisbursement.Text.Trim)
        End If
        If lblTTA.Text = String.Empty Then
            MyRow(48) = DBNull.Value
        Else
            MyRow(48) = CDbl(lblTTA.Text.Trim)
        End If
        If lblTStampingFee.Text = String.Empty Then
            MyRow(49) = DBNull.Value
        Else
            MyRow(49) = CDbl(lblTStampingFee.Text.Trim)
        End If
        If lblReferralFee.Text = String.Empty Then
            MyRow(50) = DBNull.Value
        Else
            MyRow(50) = CDbl(lblReferralFee.Text.Trim)
        End If
        MyRow(51) = GetName()
        MyRow(52) = Now()
        TempDT.Rows.Add(MyRow)

        If TempDT IsNot Nothing Then
            Dim objRDLC As New RDLC("report/rptDocRentTakeUp.rdlc", "DocRentTakeUp")
            TempDT.TableName = "dsDocRentTakeUp_AW_DocRentTakeUp"
            objRDLC.AddDatabase(TempDT)
            ReportViewer1.LocalReport.DataSources.Clear()
            ReportViewer1.LocalReport.ReportPath = "report/rptDocRentTakeUp.rdlc"
            ReportViewer1.LocalReport.DataSources.Add(New Microsoft.Reporting.WebForms.ReportDataSource(TempDT.TableName, TempDT))
            ReportViewer1.LocalReport.Refresh()
        End If
    End Sub

    Private Sub DeclareColumnTempDT(ByVal MyDT As Data.DataTable)
        Dim DocRentTitle As Data.DataColumn = New Data.DataColumn("DocRentTitle")
        DocRentTitle.DataType = System.Type.GetType("System.String")
        MyDT.Columns.Add(DocRentTitle)
        Dim DocOpenRefNo As Data.DataColumn = New Data.DataColumn("DocOpenRefNo")
        DocOpenRefNo.DataType = System.Type.GetType("System.String")
        MyDT.Columns.Add(DocOpenRefNo)
        Dim TransactionId As Data.DataColumn = New Data.DataColumn("TransactionId")
        TransactionId.DataType = System.Type.GetType("System.String")
        MyDT.Columns.Add(TransactionId)
        Dim Category As Data.DataColumn = New Data.DataColumn("Category")
        Category.DataType = System.Type.GetType("System.String")
        MyDT.Columns.Add(Category)
        Dim REN As Data.DataColumn = New Data.DataColumn("REN")
        REN.DataType = System.Type.GetType("System.String")
        MyDT.Columns.Add(REN)
        Dim Lister As Data.DataColumn = New Data.DataColumn("Lister")
        Lister.DataType = System.Type.GetType("System.String")
        MyDT.Columns.Add(Lister)
        Dim DocDate As Data.DataColumn = New Data.DataColumn("DocDate")
        DocDate.DataType = System.Type.GetType("System.DateTime")
        MyDT.Columns.Add(DocDate)
        Dim Premise As Data.DataColumn = New Data.DataColumn("Premise")
        Premise.DataType = System.Type.GetType("System.String")
        MyDT.Columns.Add(Premise)
        Dim MonthlyRental As Data.DataColumn = New Data.DataColumn("MonthlyRental")
        MonthlyRental.DataType = System.Type.GetType("System.String")
        MyDT.Columns.Add(MonthlyRental)
        Dim Duration As Data.DataColumn = New Data.DataColumn("Duration")
        Duration.DataType = System.Type.GetType("System.Double")
        MyDT.Columns.Add(Duration)
        Dim DurationType As Data.DataColumn = New Data.DataColumn("DurationType")
        DurationType.DataType = System.Type.GetType("System.String")
        MyDT.Columns.Add(DurationType)
        Dim AnotherDuration As Data.DataColumn = New Data.DataColumn("AnotherDuration")
        AnotherDuration.DataType = System.Type.GetType("System.Double")
        MyDT.Columns.Add(AnotherDuration)
        Dim AnotherType As Data.DataColumn = New Data.DataColumn("AnotherType")
        AnotherType.DataType = System.Type.GetType("System.String")
        MyDT.Columns.Add(AnotherType)
        Dim UponAt As Data.DataColumn = New Data.DataColumn("UponAt")
        UponAt.DataType = System.Type.GetType("System.String")
        MyDT.Columns.Add(UponAt)
        Dim Increase As Data.DataColumn = New Data.DataColumn("Increase")
        Increase.DataType = System.Type.GetType("System.Double")
        MyDT.Columns.Add(Increase)
        Dim CommencementDate As Data.DataColumn = New Data.DataColumn("CommencementDate")
        CommencementDate.DataType = System.Type.GetType("System.DateTime")
        MyDT.Columns.Add(CommencementDate)
        Dim PremisesUse As Data.DataColumn = New Data.DataColumn("PremisesUse")
        PremisesUse.DataType = System.Type.GetType("System.String")
        MyDT.Columns.Add(PremisesUse)
        Dim TerminationClause As Data.DataColumn = New Data.DataColumn("TerminationClause")
        TerminationClause.DataType = System.Type.GetType("System.String")
        MyDT.Columns.Add(TerminationClause)
        Dim RentFreePeriod As Data.DataColumn = New Data.DataColumn("RentFreePeriod")
        RentFreePeriod.DataType = System.Type.GetType("System.String")
        MyDT.Columns.Add(RentFreePeriod)
        Dim Requisition As Data.DataColumn = New Data.DataColumn("Requisition")
        Requisition.DataType = System.Type.GetType("System.String")
        MyDT.Columns.Add(Requisition)
        Dim LandlordName As Data.DataColumn = New Data.DataColumn("LandlordName")
        LandlordName.DataType = System.Type.GetType("System.String")
        MyDT.Columns.Add(LandlordName)
        Dim LandlordNRIC As Data.DataColumn = New Data.DataColumn("LandlordNRIC")
        LandlordNRIC.DataType = System.Type.GetType("System.String")
        MyDT.Columns.Add(LandlordNRIC)
        Dim LandlordAddress As Data.DataColumn = New Data.DataColumn("LandlordAddress")
        LandlordAddress.DataType = System.Type.GetType("System.String")
        MyDT.Columns.Add(LandlordAddress)
        Dim LandlordContactPerson As Data.DataColumn = New Data.DataColumn("LandlordContactPerson")
        LandlordContactPerson.DataType = System.Type.GetType("System.String")
        MyDT.Columns.Add(LandlordContactPerson)
        Dim LandlordTel As Data.DataColumn = New Data.DataColumn("LandlordTel")
        LandlordTel.DataType = System.Type.GetType("System.String")
        MyDT.Columns.Add(LandlordTel)
        Dim LandlordFax As Data.DataColumn = New Data.DataColumn("LandlordFax")
        LandlordFax.DataType = System.Type.GetType("System.String")
        MyDT.Columns.Add(LandlordFax)
        Dim LandlordMobile As Data.DataColumn = New Data.DataColumn("LandlordMobile")
        LandlordMobile.DataType = System.Type.GetType("System.String")
        MyDT.Columns.Add(LandlordMobile)
        Dim LandlordVMT As Data.DataColumn = New Data.DataColumn("LandlordVMT")
        LandlordVMT.DataType = System.Type.GetType("System.String")
        MyDT.Columns.Add(LandlordVMT)
        Dim AgencyFee As Data.DataColumn = New Data.DataColumn("AgencyFee")
        AgencyFee.DataType = System.Type.GetType("System.Double")
        MyDT.Columns.Add(AgencyFee)
        Dim GovTax As Data.DataColumn = New Data.DataColumn("GovTax")
        GovTax.DataType = System.Type.GetType("System.Double")
        MyDT.Columns.Add(GovTax)
        Dim GovPercent As Data.DataColumn = New Data.DataColumn("GovPercent")
        GovPercent.DataType = System.Type.GetType("System.Double")
        MyDT.Columns.Add(GovPercent)
        Dim LandlordTA As Data.DataColumn = New Data.DataColumn("LandlordTA")
        LandlordTA.DataType = System.Type.GetType("System.Double")
        MyDT.Columns.Add(LandlordTA)
        Dim LandlordStampingFee As Data.DataColumn = New Data.DataColumn("LandlordStampingFee")
        LandlordStampingFee.DataType = System.Type.GetType("System.Double")
        MyDT.Columns.Add(LandlordStampingFee)
        Dim BankAcc As Data.DataColumn = New Data.DataColumn("BankAcc")
        BankAcc.DataType = System.Type.GetType("System.String")
        MyDT.Columns.Add(BankAcc)
        Dim TenantName As Data.DataColumn = New Data.DataColumn("TenantName")
        TenantName.DataType = System.Type.GetType("System.String")
        MyDT.Columns.Add(TenantName)
        Dim TenantNRIC As Data.DataColumn = New Data.DataColumn("TenantNRIC")
        TenantNRIC.DataType = System.Type.GetType("System.String")
        MyDT.Columns.Add(TenantNRIC)
        Dim TenantAddress As Data.DataColumn = New Data.DataColumn("TenantAddress")
        TenantAddress.DataType = System.Type.GetType("System.String")
        MyDT.Columns.Add(TenantAddress)
        Dim TenantContactPerson As Data.DataColumn = New Data.DataColumn("TenantContactPerson")
        TenantContactPerson.DataType = System.Type.GetType("System.String")
        MyDT.Columns.Add(TenantContactPerson)
        Dim TenantTel As Data.DataColumn = New Data.DataColumn("TenantTel")
        TenantTel.DataType = System.Type.GetType("System.String")
        MyDT.Columns.Add(TenantTel)
        Dim TenantFax As Data.DataColumn = New Data.DataColumn("TenantFax")
        TenantFax.DataType = System.Type.GetType("System.String")
        MyDT.Columns.Add(TenantFax)
        Dim TenantMobile As Data.DataColumn = New Data.DataColumn("TenantMobile")
        TenantMobile.DataType = System.Type.GetType("System.String")
        MyDT.Columns.Add(TenantMobile)
        Dim TenantVMT As Data.DataColumn = New Data.DataColumn("TenantVMT")
        TenantVMT.DataType = System.Type.GetType("System.String")
        MyDT.Columns.Add(TenantVMT)
        Dim DepositMonth As Data.DataColumn = New Data.DataColumn("DepositMonth")
        DepositMonth.DataType = System.Type.GetType("System.Double")
        MyDT.Columns.Add(DepositMonth)
        Dim Deposit As Data.DataColumn = New Data.DataColumn("Deposit")
        Deposit.DataType = System.Type.GetType("System.Double")
        MyDT.Columns.Add(Deposit)
        Dim AdvanceMonth As Data.DataColumn = New Data.DataColumn("AdvanceMonth")
        AdvanceMonth.DataType = System.Type.GetType("System.Double")
        MyDT.Columns.Add(AdvanceMonth)
        Dim Advance As Data.DataColumn = New Data.DataColumn("Advance")
        Advance.DataType = System.Type.GetType("System.Double")
        MyDT.Columns.Add(Advance)
        Dim WEDeposit As Data.DataColumn = New Data.DataColumn("WEDeposit")
        WEDeposit.DataType = System.Type.GetType("System.Double")
        MyDT.Columns.Add(WEDeposit)
        Dim Disbursement As Data.DataColumn = New Data.DataColumn("Disbursement")
        Disbursement.DataType = System.Type.GetType("System.Double")
        MyDT.Columns.Add(Disbursement)
        Dim TenantTA As Data.DataColumn = New Data.DataColumn("TenantTA")
        TenantTA.DataType = System.Type.GetType("System.Double")
        MyDT.Columns.Add(TenantTA)
        Dim TenantStampingFee As Data.DataColumn = New Data.DataColumn("TenantStampingFee")
        TenantStampingFee.DataType = System.Type.GetType("System.Double")
        MyDT.Columns.Add(TenantStampingFee)
        Dim ReferralFee As Data.DataColumn = New Data.DataColumn("ReferralFee")
        ReferralFee.DataType = System.Type.GetType("System.Double")
        MyDT.Columns.Add(ReferralFee)
        Dim CreateBy As Data.DataColumn = New Data.DataColumn("CreateBy")
        CreateBy.DataType = System.Type.GetType("System.String")
        MyDT.Columns.Add(CreateBy)
        Dim CreateDate As Data.DataColumn = New Data.DataColumn("CreateDate")
        CreateDate.DataType = System.Type.GetType("System.DateTime")
        MyDT.Columns.Add(CreateDate)
    End Sub

    Protected Sub btnBack_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnBack.Click
        If Session("Back") Is Nothing Then
            Response.Redirect("Documentation.aspx")
        Else
            Dim strBack As String = Session("Back").ToString
            Dim arr() As String = strBack.Split("ڡ")
            Response.Redirect(arr(0).ToString)
        End If
    End Sub

    Protected Sub btnDownload_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnDownload.Click
        Dim TempDT As New Data.DataTable

        BtnSave_Click(sender, e)

        Dim CurrentUser As String = GetName()
        Dim PrintStr As String = "Printed by " & CurrentUser & " on " & Format(Now(), "dd-MMM-yyyy")

        TempDT = LoadDocRent()

        If TempDT IsNot Nothing Then
            Dim objRDLC As New RDLC("report/rptDocRentTakeUp.rdlc", "DocRentTakeUp")
            TempDT.TableName = "dsDocRentTakeUp_AW_DocRentTakeUp"
            objRDLC.AddParameter("PrintStr", PrintStr)
            objRDLC.AddDatabase(TempDT)
            objRDLC.ExportReport(RDLC.ExportTypeFormat.PDF, HttpContext.Current)
        End If
    End Sub

    Protected Sub btnBackEntry_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnBackEntry.Click
        pnlEntry.Visible = True
        pnlPreview.Visible = False
    End Sub
End Class
